package com.ldp.designpatterns.study.mediator.demo2.user;

import com.ldp.designpatterns.study.mediator.demo2.chatMediator.ChatMediator;
import lombok.Data;

/**
 * @ClassName User
 * @Description  TODO: 中介者模式：中介者模式引入了一个中介者对象，它负责协调和管理对象之间的通信。对象不再直接与其他对象通信，而是通过中介者来发送和接收消息
 * @Author lindipei
 * @Date 2023/10/18 15:37
 */
@Data
public class User {
    private String name;
    private ChatMediator mediator;

    public User(String name, ChatMediator mediator) {
        this.name = name;
        this.mediator = mediator;
    }

    public void sendMessage(String message) {
        System.out.println(name + " 发送消息: " + message);
        mediator.sendMessage(message, this);
    }

    public void receiveMessage(String message) {
        System.out.println(name + " 收到消息: " + message);
    }

}
